package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 添加菜品或套餐分类
     *
     * @param category
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user) " +
            "VALUES (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void insertCate(Category category);

    /**
     * 分页查询
     *
     * @param name
     * @param type
     * @return
     */
    Page<Category> pageQuery(String name, Integer type);

    /**
     * 根据id删除分类
     *
     * @param id
     */
    @Delete("delete from category where id = #{id} ")
    void deleteCate(Long id);

    /**
     * 修改分类信息
     *
     * @param category
     */
    @AutoFill(OperationType.UPDATE)
    void updateCate(Category category);

    /**
     * 根据类型查询分类
     *
     * @param type
     * @return
     */
    List<Category> queryByType(Integer type);

    /**
     * 查询分类
     *
     * @return
     */
    @Select("select * from category order by create_time desc")
    List<Category> list();
}
